package com.atguigu.activemq.transportTestNio;

import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;
public class JmsProduce {
    public static final String ACTIVEMQ_URL="tcp://124.70.84.192:61618";
    public static final String QUEUE_NAME="Transport-nio+auto";
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory=new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(QUEUE_NAME);
        Destination destination = session.createQueue(QUEUE_NAME);//也可以直接用目的地类
        MessageProducer messageProducer = session.createProducer(queue);
        messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for (int i=1;i<4;i++){
            //7、创建消息（发送字符串）
            TextMessage textMessage = session.createTextMessage("我发送的第" + i + "条消息");
            textMessage.setStringProperty("c01","vip");
            textMessage.setIntProperty("vip",8);
            textMessage.setBooleanProperty("vip8",true);
            messageProducer.send(textMessage);
        }
        messageProducer.close();
        session.close();
        connection.close();
        System.out.println("连接中断");
    }
}

